package com.dxysun.design.responsiblity.builder;

public abstract class Handler
{

	protected Handler nextHandler;

	public void next(Handler nextHandler)
	{
		this.nextHandler = nextHandler;
	}

	abstract void handlerRequest(String req);

	public static class Builder
	{
		private Handler head;
		private Handler tail;

		public Builder addHandler(Handler handler)
		{
			if (this.head == null)
			{
				this.head = this.tail = handler;
				return this;
			}
			this.tail.next(handler);
			this.tail = handler;
			return this;
		}

		public Handler build()
		{
			return this.head;
		}
	}
}
